package rule

import (
	"strconv"
)

func init() {
	Register(&floatRule{})
}

type floatRule struct{}

func (f *floatRule) Name() string {
	return "float"
}

func (f *floatRule) Check(in *RuleInput) (err error) {
	if in.Value != nil {
		switch in.Value.(type) {
		case bool:
			return
		case string:
			if _, err1 := strconv.ParseFloat(in.Value.(string), 64); err1 == nil {
				return
			}
		}
	}
	return in.Error()
}
